import * as Utils from 'utils.js';

var Recever = "";
/**速云报表api**/
/**
 *查询全部商品
 */
export function GetBarcodeGoodsMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_BarcodeGoodsMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}


/**
 *条码扫描商品
 */
export function GetBarcodeGoodsMessageModel(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_BarcodeGoodsMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	console.log(data);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

/**
 * @param {Object} GoodImagePath采购类查供应商的接口
 */
export function GetClientPurMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_ClientMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//价格跟踪
export function XH_Get_PriceFollowMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/XH_Get_PriceFollowMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
/**
 * @param {Object} GoodImagePath采购类查供应商的接口
 */
export function GetClientSaleMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_ClientMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

/**
 * @param {Object} 查询往来单位
 */
export function GetClientMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_ClientMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
/**
 * @param {Object} GoodImagePath查询仓库档案
 */
export function GetStoreMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_Bill_StoreMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

/**
 * @param {Object} GoodImagePath查询业务员
 */
export function GetOperatorMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_OperatorMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

/**
 * @param {Object} GoodImagePath查询银行账户
 */
export function GetBankMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_BankMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}


//转账方式
export function GetPayModeMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_PayModeMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
/**
 * @param {Object} 付款单。查询应付单据接口
 */
export function GetPayBill(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_Pay_Bill");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

/**
 * @param {Object} 收款单。查询应收接口
 */
export function GetReceivBill(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_Receiv_Bill");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}


/**
 * @param {Object} 获取单号
 */
export function NewOrderNo(arr, callBack) {
	let url = Utils.getPostIp("/api/NewOrderNo");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//获取全部商品
export function GetGoodsMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_GoodsMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//查询商品批号
export function XHGetBatchNoFollow(arr, callBack) {
	let url = Utils.getPostIp("/api/XH_Get_BatchNoFollow");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//价格跟踪
// export function XH_Get_PriceFollowMessage(arr, callBack) {
// 	let url = Utils.getPostIp("/api/XH_Get_PriceFollowMessage");
// 	var responseArr = {};
// 	let data = Utils.getData(arr);
// 	Utils.httpGetClient(url, data, "GET", function(data, state) {
// 		responseArr.data = data.data;
// 		responseArr.state = state;
// 		callBack(responseArr);
// 	});
// }
//获取多单位
export function Get_GoodsUnitMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_GoodsUnitMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//保存单据
export function AddBillOrder(arr, callBack) {
	let url = Utils.getPostIp("/api/Add_Bill_Order");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//保存单据(采购入库单，采购退货单，销售出库单，销售退货单，调拨单，其他入库单，其他出库单 ，配送申请单，配送出库单，配送退回单)
export function AddBill(arr, callBack) {
	let url = Utils.getPostIp("/api/Add_Bill");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//保存单据(收款单，付款单，会员充值)
export function AddBillPay(arr, callBack) {
	let url = Utils.getPostIp("/api/Add_Bill_Pay");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//保存单据(盘点单)
export function AddBillInventory(arr, callBack) {
	let url = Utils.getPostIp("/api/Add_Bill_Inventory");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//查询批次(盘点单)
export function GetInventoryMessage(arr, callBack) {
	let url = Utils.getPostIp("/api/Get_InventoryMessage");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//查询商品批号(盘点单)
// export function XHGetBatchNoFollow(arr, callBack) {
// 	let url = Utils.getPostIp("/api/XH_Get_BatchNoFollow");
// 	var responseArr = {};
// 	let data = Utils.getData(arr);
// 	Utils.httpGetClient(url, data, "GET", function(data, state) {
// 		responseArr.data = data.data;
// 		responseArr.state = state;
// 		callBack(responseArr);
// 	});
// }


//查询商品库存
export function SelectStockNum(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_StockNum");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//查询订单
export function SelectBillOrderMaster(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Order_Master");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}




//查询订单明细
export function SelectBillOrderDetail(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Order_Detail");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}


//查询订单 (采购入库单，采购退货单，销售出库单，销售退货单，调拨单，其他入库单，其他出库单 ，配送申请单，配送出库单，配送退回单，POS单)
export function SelectBillMaster(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Master");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//查询订单明细(采购入库单，采购退货单，销售出库单，销售退货单，调拨单，其他入库单，其他出库单 ，配送申请单，配送出库单，配送退回单，POS单)
export function SelectBillDetail(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Detail");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//查询订单(收款单，付款单，会员充值)
export function SelectBillPay(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Pay");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//查询订单明细(收款单，付款单，会员充值)
export function SelectBillPayDetail(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Pay_Detail");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//查询订单 (盘点单)
export function SelectBillInventory(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Inventory");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//查询订单明细 (盘点单)
export function SelectBillInventoryDetail(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Bill_Inventory_Detail");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//修改单据（采购销售促销）
export function Change_Bill_Order(arr, callBack) {
	let url = Utils.getPostIp("/api/Change_Bill_Order");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//修改单据（采购入库单，采购退货单，销售出库单，销售退货单，调拨单，其他入库单，其他出库单 ，配送申请单，配送出库单，配送退回单）
export function Change_Bill(arr, callBack) {
	let url = Utils.getPostIp("/api/Change_Bill");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//修改单据（付款单，收款单，会员充值）
export function Change_Bill_Pay(arr, callBack) {
	let url = Utils.getPostIp("/api/Change_Bill_Pay");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//修改单据（盘点单）
export function Change_Bill_Inventory(arr, callBack) {
	let url = Utils.getPostIp("/api/Change_Bill_Inventory");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//单据审核
export function Bill_Check(arr, callBack) {
	let url = Utils.getPostIp("/api/Bill_Check");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//单据反审核
export function Bill_Check_Reverse(arr, callBack) {
	let url = Utils.getPostIp("/api/Bill_Check_Reverse");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//新增盘点批次

export function Add_Inventorybatch(arr, callBack) {
	let url = Utils.getPostIp("/api/Add_Inventorybatch");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//获取可以删除或结束的盘点批次

export function Select_Inventorybatch(arr, callBack) {
	let url = Utils.getPostIp("/api/Select_Inventorybatch");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "GET", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//删除盘点批次
export function Delete_Inventorybatch(arr, callBack) {
	let url = Utils.getPostIp("/api/Delete_Inventorybatch");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}


//结束盘点批次
export function End_Inventorybatch(arr, callBack) {
	let url = Utils.getPostIp("/api/End_Inventorybatch");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}
//远程打印
export function Add_Android_Print(arr, callBack) {
	let url = Utils.getPostIp("/api/Add_Android_Print");
	var responseArr = {};
	let data = Utils.getData(arr);
	Utils.httpGetClient(url, data, "POST", function(data, state) {
		responseArr.data = data.data;
		responseArr.state = state;
		callBack(responseArr);
	});
}

//审核单据
// export function Bill_Check(arr,callBack) {
// 	let url = Utils.getPostIp("/api/Bill_Check");
// 	var responseArr = {};
// 	let data = Utils.getData(arr);
// 	Utils.httpGetClient(url, data, "POST", function(data, state) {
// 		responseArr.data = data.data;
// 		responseArr.state = state;
// 		callBack(responseArr);
// 	});
// }

//反审核单据
// export function Bill_Check_Reverse(arr,callBack) {
// 	let url = Utils.getPostIp("/api/Bill_Check_Reverse");
// 	var responseArr = {};
// 	let data = Utils.getData(arr);
// 	Utils.httpGetClient(url, data, "POST", function(data, state) {
// 		responseArr.data = data.data;
// 		responseArr.state = state;
// 		callBack(responseArr);
// 	});
// }

//图片路径处理
export function setImageUrl(GoodImagePath) {
	//ip
	var ip = uni.getStorageSync("ip");
	//端口
	var ipPost = uni.getStorageSync("ipPost");

	if (GoodImagePath == "") {
		return '/static/default1.jpg';
	} else {
		let path = "http://" + ip;
		if (ipPost != "") {
			path += ":" + ipPost;
		}
		console.log(path + "/picture" + GoodImagePath);
		return path + "/picture" + GoodImagePath;
	}
}


//提示框
export function showTip(msg) {
	uni.showToast({
		position: 'bottom',
		title: msg,
		duration: 1000,
		style: "z-index:9999",
	});
};

//确认框
export function showConfirm(msg, sureClick) {
	uni.showModal({
		title: '提示',
		content: msg,
		style: "z-index:9999",
		success: function(res) {
			if (res.confirm) {
				sureClick(true);
			} else if (res.cancel) {
				sureClick(false);
			}
		}
	});
}


//注册监听器
export function registerReciver(success) {

	var receiver;
	var main;
	main = plus.android.runtimeMainActivity(); //获取activity
	receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
		onReceive: function(context, intent) { //实现onReceiver回调函数
			plus.android.importClass(intent); //通过intent实例引入intent类，方便以后的‘.’操作
			// console.log(intent.getStringExtra("data")); //获取条码内容
			// Api.showTip(intent.getStringExtra("data"));
			success(intent.getStringExtra("data"));
		}
	});
	Recever = receiver;
	var IntentFilter = plus.android.importClass('android.content.IntentFilter');
	var Intent = plus.android.importClass('android.content.Intent');
	var filter = new IntentFilter();
	filter.addAction("com.rscja.android.DATA_RESULT"); //监听条码广播
	main.registerReceiver(receiver, filter); //注册监听
}

//反注册广播
export function unRegisterReciver(success) {

	// var receiver;
	var main;
	main = plus.android.runtimeMainActivity(); //获取activity
	main.unregisterReceiver(Recever); //注册监听
}
//保留两位小数
export function setTwoFloat(num) {
	return Math.round(num * 100) / 100;
}
